package cn.hnc.checkapi.controller;

import cn.hnc.checkapi.bean.User;
import cn.hnc.checkapi.bean.datatmp.UserData;
import cn.hnc.checkapi.bean.response.SimpleResponseEntity;
import cn.hnc.checkapi.logger.WaLogger;
import cn.hnc.checkapi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
   @Autowired
   private UserService userService;

   @PostMapping({"/checkapi/login"})
   @ResponseBody
   public SimpleResponseEntity login(@RequestBody User user) {
      SimpleResponseEntity simpleResponseEntity = new SimpleResponseEntity();

      try {
         this.userService.login(user);
         simpleResponseEntity.setMsgCode(0);
         simpleResponseEntity.setMsgDesc("登录成功");
      } catch (Exception var4) {
         Exception e = var4;
         simpleResponseEntity.setMsgCode(1);
         simpleResponseEntity.setMsgDesc(e.toString());
         WaLogger.logger.warn(e.toString());
      }

      return simpleResponseEntity;
   }

   @PostMapping({"/checkapi/updatePassword"})
   @ResponseBody
   public SimpleResponseEntity updatePassword(@RequestBody UserData userData) {
      SimpleResponseEntity simpleResponseEntity = new SimpleResponseEntity();

      try {
         this.userService.updatePassword(userData.getUsername(), userData.getPassword(), userData.getNewPassword());
         simpleResponseEntity.setMsgCode(0);
         simpleResponseEntity.setMsgDesc("修改成功");
      } catch (Exception var4) {
         Exception e = var4;
         simpleResponseEntity.setMsgCode(1);
         simpleResponseEntity.setMsgDesc(e.toString());
         WaLogger.logger.warn(e.toString());
      }

      return simpleResponseEntity;
   }
}
